home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / gt_power / gtuser11.zip / GTUSER.PAS < prev    next >
Pascal/Delphi Source File  |  1991-02-06  |  10KB  |  371 lines

  1. unit GTUser;
  2. { A unit to parse the GT Powercomm GTUSER.BBS file and provide a
  3.   pre-digested record for door or companion programs. This should save
  4.   writers of such utilities considerable "wheel-reinventing".
  5.  
  6.   It is current as at the format used by GT 16 and is backward-compatible
  7.   with earlier releases.
  8.  
  9.   Copyright (C) Ted Harper 1990-91
  10.  
  11.   but free distribution of _unmodified_ source and generated code permitted.
  12.  
  13.   Amendments :-
  14.   -------------
  15.   Corrected bug where date is preceded by _two_ blanks             t.h. 2/91
  16.   Stopped using "FSearch" builtin because of undocumented feature  t.h. 2/91
  17. }
  18.  
  19. interface
  20. const
  21.    GTUSER_Name_Length = 32;
  22.  
  23. type
  24.    GTUSER_Name_Type = string[GTUSER_Name_Length];
  25.  
  26.    GTUSER_Date_Type = record
  27.       YYYY : word;
  28.       MM,
  29.       DD : byte
  30.       end;
  31.  
  32.    GTUSER_Time_Type = record
  33.       HH,
  34.       MM,
  35.       SS : byte
  36.       end;
  37.  
  38.    GTUSER_Timelimit_Type = integer;
  39.  
  40.    Authorisations = (
  41.       UP,      { Uploads permitted }
  42.       DN,      { Downloads permitted }
  43.       PR,      { Private mail may be entered }
  44.       KL,      { Can K)ill messages like sysop }
  45.       SY,      { SYSOP }
  46.       CH,      { Manual dir. change allowed (if GTDIR.BBS not in use) }
  47.       SH,      { Shell to DOS allowed }
  48.       DR,      { Use of DOORs by user OK }
  49.       MS,      { Messages may be read }
  50.       FA,      { Allow FileAttach when netmailing }
  51.       FR,      { Allow FileRequest when netmailing }
  52.       NL,      { Disable L)ist directory main menu option }
  53.       NE,      { Disable E)nter message command }
  54.       CB,      { CB simulator use allowed }
  55.       NP,      { Sysop page _not_ allowed }
  56.       DX);     { Delivery (??) allowed }
  57.  
  58.    Authorisation_Set = set of Authorisations;
  59.  
  60.    GTUSER_BBS_Details = record
  61.       Level : char;
  62.       First_Name,
  63.       Last_Name : GTUSER_Name_Type;
  64.       Authorisation : Authorisation_Set;
  65.       DCE_Baud,
  66.       DTE_Baud : word; { 0 = local }
  67.       Ansi_Opt : boolean;
  68.       Date_Last_On : GTUSER_Date_Type;
  69.       Limit,
  70.       Event : GTUSER_TimeLimit_Type;
  71.       Current_Time : GTUSER_Time_Type
  72.       end;
  73.  
  74. procedure GetGTUserDetails(var GBD : GTUSER_BBS_Details);
  75.  
  76. implementation
  77.  
  78. uses
  79.    DOS;
  80.  
  81. const
  82.    GTUSER_BBS_FileName = 'GTUSER.BBS';
  83.  
  84.    GTUSER_BBS_Length = 250;
  85.  
  86.    GTUSER_Word_Length = 60;
  87.    GTUSER_Word_array_Limit = 12;
  88.  
  89. type
  90.    GTUSER_BBS_Rec_Type = string[GTUSER_BBS_Length];
  91.  
  92.    GTUSER_Word = string[GTUSER_Word_Length];
  93.    GTUSER_Word_Array_Type = array [1..GTUSER_Word_Array_Limit] of GTUSER_Word;
  94.  
  95. var
  96.    GTUSER_BBS_File : text;
  97.  
  98.    GTUSER_BBS_Rec : GTUSER_BBS_Rec_Type;
  99.  
  100.  
  101. procedure Get_File_Details(var G : GTUSER_BBS_Rec_Type);
  102. { Find the GTUSER.BBS file and read into "G" }
  103. var
  104.    GTPath, GTUSERBBS_PATH : PathStr;
  105. begin
  106.    { Find GTUSER.BBS in the directory pointed to by GTPATH }
  107.    GTPath := getenv('GTPATH');
  108.    if GTPath = ''
  109.    then begin
  110.       writeln('GTUSER : Can''t find GTPATH environment variable');
  111.       halt(1)
  112.       end;
  113.  
  114.    if copy(GTPath,length(GTPath),1) <> '\'
  115.    then
  116.       GTPath := GTPath + '\';
  117.  
  118.    GTUSERBBS_PATH := GTPath + GTUSER_BBS_FileName;
  119.  
  120.    assign(GTUSER_BBS_File,GTUSERBBS_PATH);
  121.    {$I-}
  122.    reset(GTUSER_BBS_File);
  123.    {$I+}
  124.    if IOResult <> 0
  125.    then begin
  126.       writeln('GTPATH : GTUSER.BBS could not be found in GTPATH directory');
  127.       halt(1)
  128.       end;
  129.  
  130.    readln(GTUSER_BBS_File,G);
  131.    close(GTUSER_BBS_File)
  132. end; { Get_File_Details }
  133.  
  134.  
  135. procedure Break_Into_Words(GBR : GTUSER_BBS_Rec_Type;
  136.                            var Words : GTUSER_Word_Array_Type);
  137. var
  138.    i : byte;
  139.    WordIndex : byte;
  140. begin
  141.    WordIndex := 0;
  142.    for i := 1 to GTUSER_Word_array_Limit
  143.    do
  144.       Words[i] := '';
  145.    i := 1;
  146.  
  147.    while ((i <= length(GBR)) and (WordIndex < GTUSER_Word_array_limit))
  148.    do begin
  149.       { Get a complete "word" - delimited by space or eoln }
  150.       inc(WordIndex);
  151.       while ((i <= length(GBR)) and (GBR[i] <> ' '))
  152.       do begin
  153.          Words[WordIndex] := Words[WordIndex] + GBR[i];
  154.          inc(i);
  155.          end;
  156.       { End of word has been reached - skip past spaces }
  157.       while ((i <= length(GBR)) and (GBR[i] = ' '))
  158.       do
  159.          inc(i)
  160.       end
  161. end; { Break_Into_Words }
  162.  
  163.  
  164. procedure Get_Authorisation(User_Auth : GTUSER_Word;
  165.                             var AS : Authorisation_Set);
  166. { Parse string of all authorisations given to the current user and
  167.   return a set of authorisations. }
  168. const
  169.    Num_Auths = 16;
  170.  
  171.    AU_Str : array[1..Num_Auths] of string[2] =
  172.      ('UP','DN','PR','KL','SY','CH','SH','DR','MS','FA',
  173.       'FR','NL','NE','CB','NP','DX');
  174.    AU_Val : array[1..Num_Auths] of Authorisations =
  175.      ( UP , DN , PR , KL , SY , CH , SH , DR , MS , FA ,
  176.        FR , NL , NE , CB , NP , DX );
  177. var
  178.    i : byte;
  179. begin
  180.    AS := [];
  181.  
  182.    for i := 1 to Num_Auths
  183.    do begin
  184.       if pos(AU_Str[i],User_Auth) > 0
  185.       then
  186.          AS := AS + [(AU_Val[i])]
  187.       end
  188. end; { Get_Authorisation }
  189.  
  190.  
  191. procedure Get_Baud(User_Baud : GTUSER_Word;
  192.                    var DCE_Baud, DTE_Baud : word);
  193. { Get current user's baud rate and return as numeric (LOCAL = 0) }
  194. var
  195.    Comma_Pos : byte;
  196.    Temp_Word : GTUSER_Word;
  197.    code : integer;
  198. begin
  199.    if User_Baud = 'LOCAL'
  200.    then begin
  201.       DCE_Baud := 0;
  202.       DTE_Baud := 0
  203.       end
  204.    else begin
  205.       { With latest GT host changes, both DCE and DTE baud rates are
  206.         returned separated by a comma }
  207.       Comma_Pos := pos(',',User_Baud);
  208.       if Comma_Pos = 0
  209.       then begin
  210.          { Earlier version of GT - only one value returned, assume same for
  211.            DCE and DTE }
  212.          val(User_Baud,DCE_Baud,Code);
  213.          if Code <> 0
  214.          then
  215.             DCE_Baud := 0;
  216.          DTE_Baud := DCE_Baud
  217.          end
  218.       else begin
  219.          { If there is a comma in the string, then _two_ numbers are there }
  220.  
  221.          { Get first number (DTE baud) and convert to numeric }
  222.          Temp_Word := copy(User_Baud,1,pred(Comma_Pos));
  223.          val(Temp_Word,DTE_Baud,Code);
  224.          if Code <> 0
  225.          then
  226.             DTE_Baud := 0;
  227.  
  228.          { Get second number (DCE baud) and convert to numeric }
  229.          Temp_Word := copy(User_Baud,succ(Comma_Pos),
  230.                          length(User_Baud)-Comma_Pos);
  231.          val(Temp_Word,DCE_Baud,Code);
  232.          if Code <> 0
  233.          then
  234.             DCE_Baud := 0
  235.          end
  236.       end
  237. end; { Get_Baud }
  238.  
  239.  
  240. procedure Get_Last_Date(Date_Str : GTUSER_Word;
  241.                         var Last_Date : GTUSER_Date_Type);
  242. { Parse date into years, months and days (separately) and return as such }
  243. const
  244.    DATE_DELIMITER = '-';
  245. var
  246.    Work_Date, Temp_Str : string;
  247.    Month_End, Day_End : byte;
  248.    code : integer;
  249. begin
  250.    with Last_Date
  251.    do begin
  252.       YYYY := 0;
  253.       MM := 0;
  254.       DD := 0
  255.       end;
  256.  
  257.    Work_Date := Date_Str;
  258.  
  259.    { Months are the part up to the first '-' }
  260.    Month_End := pos(DATE_DELIMITER,Work_Date);
  261.    { grab characters up to (not including) the '-' }
  262.    Temp_Str := copy(Work_Date,1,pred(Month_End));
  263.    { Delete MM- from string }
  264.    delete(Work_Date,1,Month_End);
  265.    { Convert month to numeric }
  266.    val(Temp_Str,Last_Date.MM,code);
  267.  
  268.    { Extract DD part of date }
  269.    Day_End := pos(DATE_DELIMITER,Work_Date);
  270.    { grab characters up to (not including) the '-' }
  271.    Temp_Str := copy(Work_Date,1,pred(Day_End));
  272.    { Delete DD- from string }
  273.    delete(Work_Date,1,Day_End);
  274.    { Convert day to numeric }
  275.    val(Temp_Str,Last_Date.DD,code);
  276.  
  277.    { Remainder should be year as YY }
  278.    val(Work_Date,Last_Date.YYYY,code);
  279.    if Last_Date.YYYY < 100
  280.    then
  281.       { expand year to 19xx }
  282.       inc(Last_Date.YYYY,1900);
  283.  
  284. end; { Get_Last_Date }
  285.  
  286.  
  287. procedure Get_Timelimit(Limit_Str : GTUSER_Word;
  288.                         var Limit_Num : GTUSER_Timelimit_Type);
  289. { Convert a time limit from a string to a usable numeric format }
  290. var
  291.    code : integer;
  292. begin
  293.    val(Limit_Str,Limit_Num,code);
  294.    if code <> 0
  295.    then begin
  296.       { Should HALT here! }
  297.       Limit_Num := 0
  298.       end
  299. end; { Get_TimeLimit }
  300.  
  301.  
  302. procedure Get_Current_Time(Time_Str : GTUSER_Word;
  303.                         var Curr_Time : GTUSER_Time_Type);
  304. { Parse time into hours, minutes and seconds (separately) and return as such }
  305. const
  306.    TIME_DELIMITER = ':';
  307. var
  308.    Work_Time, Temp_Str : string;
  309.    Hour_End : byte;
  310.    code : integer;
  311.  
  312. begin
  313.    with Curr_Time
  314.    do begin
  315.       HH := 0;
  316.       MM := 0;
  317.       SS := 0;
  318.       end;
  319.  
  320.    Work_Time := Time_Str;
  321.  
  322.    { Extract HH part of time }
  323.    Hour_End := pos(TIME_DELIMITER,Work_Time);
  324.    { grab characters up to (not including) the ':' }
  325.    Temp_Str := copy(Work_Time,1,pred(Hour_End));
  326.    { Delete HH- from string }
  327.    delete(Work_Time,1,Hour_End);
  328.    { Convert hours to numeric }
  329.    val(Temp_Str,Curr_Time.HH,code);
  330.  
  331.    { Remainder should be minutes as MM }
  332.    val(Work_Time,Curr_Time.MM,code)
  333. end; { Get_Current_Time }
  334.  
  335.  
  336. procedure GetGTUserDetails(var GBD : GTUSER_BBS_Details);
  337. { Locate the GTUSER.BBS file and extract user details, parse and digest,
  338.   return the details to the caller.
  339. }
  340. var
  341.    GTUSER_Word_Array : GTUSER_Word_Array_Type;
  342. begin
  343.    { Locate GTUSER.BBS and read into a one-line record }
  344.    Get_File_Details(GTUSER_BBS_Rec);
  345.  
  346.    { Break input record into "words" to make later processing easier }
  347.    Break_into_Words(GTUSER_BBS_Rec,GTUSER_Word_Array);
  348.  
  349.    { simple string->string assignments }
  350.    GBD.Level      := GTUSER_Word_Array[1][1];
  351.    GBD.First_Name := GTUSER_Word_Array[2];
  352.    GBD.Last_Name  := GTUSER_Word_Array[3];
  353.  
  354.    Get_Authorisation(GTUSER_Word_Array[4],GBD.Authorisation);
  355.  
  356.    Get_Baud(GTUSER_Word_Array[5],GBD.DCE_Baud,GBD.DTE_Baud);
  357.  
  358.    GBD.Ansi_Opt := GTUSER_Word_Array[6] = 'ANSI';
  359.  
  360.    Get_Last_Date(GTUSER_Word_Array[7],GBD.Date_Last_On);
  361.  
  362.    Get_TimeLimit(GTUSER_Word_Array[8],GBD.Limit);
  363.    Get_TimeLimit(GTUSER_Word_Array[9],GBD.Event);
  364.  
  365.    Get_Current_Time(GTUSER_Word_Array[10],GBD.Current_Time)
  366.  
  367. end; { GetGTUserDetails }
  368.  
  369.  
  370. begin
  371. end.